package com.kingyea.mobilepolice.permission.service;

import com.kingyea.mobilepolice.permission.bean.Permission;
import com.kingyea.mobilepolice.permission.bean.PermissionCondition;
import com.kingyea.mobilepolice.permission.bean.PermissionPo;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @author Mr.Lin
 * @version v1.0.0
 * @description Permission 接口
 * @date Created in 2018-03-30 15:27:53
 */
public interface PermissionService {

    /**
     * 通过ID查找对象
     *
     * @param id
     * @return
     */
    Permission getById(Integer id) throws Exception;

    /**
     * 列表
     *
     * @param condition
     * @return
     */
    List<Permission> search(PermissionCondition condition);

    /**
     * 删除 软删除
     *
     * @param id
     * @return
     */
    boolean deleteById(Integer id) throws Exception;

    /**
     * 添加
     *
     * @param permission
     * @return
     */
    Permission save(Permission permission) throws Exception;

    /**
     * 更新
     *
     * @param permission
     * @return
     */
    Permission update(Permission permission) throws Exception;

    /**
     * @Description: 封装所有[有关联]的角色和资源
     * @Param: []
     * @return: java.util.Map<java.lang.String                                                                                                                                                                                                                                                               ,                                                                                                                                                                                                                                                               java.util.Collection                                                                                                                                                                                                                                                               <                                                                                                                                                                                                                                                               org.springframework.security.access.ConfigAttribute>>
     * @Author: cxc
     * @Date: 2018.04.03 10:52
     */
    Map<String, Collection<ConfigAttribute>> allPermissionRolesMap();

    /**
     * @Description: 把角色和资源都封装成指定的一个字符串集合
     * @Param: [userId]
     * @return: java.util.Collection<org.springframework.security.core.authority.SimpleGrantedAuthority>
     * @Author: cxc
     * @Date: 2018.04.04 15:05
     */
    Collection<SimpleGrantedAuthority> allRoleAndPermissionByUserId(String userId);

    /**
     * @Description: 用户的资源权限集合
     * @Param: [userId]
     * @return: java.util.List<com.kingyea.mobilepolice.permission.bean.Permission>
     * @Author: cxc
     * @Date: 2018.04.12 11:26
     */
    List<Permission> myPermissions(String userId);

    /**
     * @Description: 为角色绑定权限
     * @Param: [po]
     * @return: com.kingyea.mobilepolice.permission.bean.Permission
     * @Author: cxc
     * @Date: 2018.04.04 16:28
     */
    boolean addPermissionsForRoleId(PermissionPo po);

    /**
     * @Description: 为角折删除权限依赖
     * @Param: [po]
     * @return: com.kingyea.mobilepolice.permission.bean.Permission
     * @Author: cxc
     * @Date: 2018.04.05 11:49
     */
    boolean delPermissionsForRoleId(PermissionPo po);

    List<Permission> searchByRoleId(Integer roleId);
}
